package com.gougou.manager.web.controller.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.gougou.common.entity.EasyUIResult;
import com.gougou.manager.pojo.TbContent;
import com.gougou.manager.pojo.TbItem;
import com.gougou.manager.service.MPTbContentService;
import com.gougou.manager.service.MPTbItemService;
import com.gougou.manager.web.controller.TbContentController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/contentApi")
public class IndexApi {
    // 拿到当前类的日志对象
    private static final Logger LOGGER = LoggerFactory.getLogger(TbContentController.class);

    @Autowired
    private MPTbContentService tbContentService;


    /**
     * 分页查询内容管理信息
     * @param page 当前页
     * @param rows 页容量
     * @return
     */
    @RequestMapping("/content")
    public List getPageItem(@RequestParam Long categoryId, @RequestParam(defaultValue ="1" )int page, @RequestParam(defaultValue ="6" )int rows){
        try {
            EasyUIResult easyUIResult = new EasyUIResult();

            EntityWrapper<TbContent> contentWrapper = new EntityWrapper<TbContent>();
            contentWrapper.where("category_id = {0}",categoryId);
            contentWrapper.orderBy("created desc");//按照创建时间倒序
            //查询数据
            return tbContentService.selectPage(new Page(page, rows),contentWrapper).getRecords();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
